<?php
	
	//载入数据库文件
	require("data.php");
	$sql="select * from soul order by rand() limit 1";
	$result=mysqli_query($conn,$sql);
	$row=mysqli_fetch_assoc($result);
	
	if(is_array($_GET)&&count($_GET)>0)//先判断是否通过get传值了
    {
        if(isset($_GET["encode"]))//是否存在"id"的参数
        {
            if($_GET['encode']=='json'){
				//设置json格式头部
				header('Content-type: application/json');
				echo json_encode(array('code'=>200,'content'=>$row['content']),JSON_UNESCAPED_UNICODE);
			}elseif($_GET['encode']=='text'){
				//设置text格式头部
				header("Content-Type: text/html;charset=utf-8");
				echo $row['content'];
			}elseif($_GET['encode']=='js'){
				//输出js格式
				header("Content-Type: text/html;charset=utf-8");
				echo "function api(){document.write('" . $row['content'] ."');}";
			}else{
				//无参数时输出
				header("Content-Type: text/html;charset=utf-8");
				echo "参数错误";
			}
        }	
	}else{
		header("Content-Type: text/html;charset=utf-8");
		echo "请输入参数";
	}

?>		